/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ru.prjpeople.model.controller;

import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import ru.prjpeople.model.Person;
import ru.prjpeople.model.Position;

/**
 *
 * @author Vladimir
 */
public class PersonController {
    private static Map<Integer, Person> personsMap =
            new ConcurrentHashMap<Integer, Person>();

    static {
        addPerson(new Person("Пупкин", "Василий", "Иванович", Position.Director));
        addPerson(new Person("Иванов", "Александр", "Юрьевич", Position.Manager));
        addPerson(new Person("Глебов", "Кирилл", "Петрович", Position.Cleaner));
    }

    public static void addPerson(Person newPerson) {
        personsMap.put(newPerson.getKey(), newPerson);
    }

    public static void removePersonByKey(int key) {
        personsMap.remove(key);
    }

    public static void removePerson(Person p) {
        personsMap.remove(p.getKey());
    }

    public static int getSize() {
        return personsMap.size();
    }

    public static Person getPerson(int key) {
        return personsMap.get(key);
    }

    public static Collection<Person> getPersons() {
        return personsMap.values();
    }

    public static void clear() {
        personsMap.clear();
    }
}